#!/bin/bash
server_ip=101.201.149.229
server_path=/home/wwwroot/jcw

test_ip=115.28.130.149
test_path=/alidata/www/hlsweb/v1


ip=$1_ip
path=$1_path


if [ ! ${!ip} ]; then
  echo "==============================="
  echo "========    Warning    ========"
  echo "==============================="
  echo "Parameters not found!"
  echo "eg: ./deploy server small"
  echo "eg: ./deploy server all"
  echo "eg: ./deploy test protected/controllers"
  echo "==============================="
  exit
else
  echo "==============================="
  echo "======== deploy target ========"
  echo "==============================="
  echo ${!ip}
  echo ${!path}
  echo "==============================="
fi


rm -rf server.tar.gz

case "$2" in
	small)
	tar zcvf server.tar.gz --exclude='.sass-cache' --exclude='js/' --exclude='images/' --exclude='.idea/' --exclude='css/' --exclude='yingyou/' --exclude='uploads/' --exclude='.git'  --exclude='docs'  --exclude='server.tar.gz' --exclude='s' --exclude='*.db' --exclude='protected/apples-group.json' --exclude='._.gitignore' --exclude='.gitignore' --exclude='assets/' --exclude='protected/runtime/' .
	;;

	all|"")
	tar zcvf server.tar.gz --exclude='.sass-cache' --exclude='uploads/' --exclude='.idea/' --exclude='yingyou/' --exclude='.git'  --exclude='docs'  --exclude='server.tar.gz' --exclude='s' --exclude='*.db' --exclude='protected/apples-group.json' --exclude='._.gitignore' --exclude='.gitignore' --exclude='assets/' --exclude='protected/runtime/' .
	;;

	*)
	find $2 -name "*" | tar -czvf server.tar.gz --files-from -
	;;
esac

echo package success , start upload!

echo "==============================="
scp server.tar.gz root@${!ip}:${!path}/
ssh root@${!ip} "${!path}/conf/server.sh ${!path}"
rm -rf server.tar.gz

echo `date` >> conf/log
echo "./deploy $1 $2" >> conf/log
echo "===============================" >> conf/log
echo log success
echo "==============================="
echo success!
say "so good!" 